﻿<?php 
include_once("../function.php");
if(!isset($_COOKIE["username"])){
	msg("您还没有登录，请先登录","login.php");
}
extract($_GET);
if(isset($color)&&$color[0]=="#"){
$color=substr($color,1);
}
//print_r($_COOKIE['username']);//wanmingming
$name=$_COOKIE['username'];
$sql="select * from ts_user where username='$name'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)==1)
	{
		$one=mysqli_fetch_assoc($res);
		$uid=$one['uid'];
	}
}
$sql="select * from ts_cart where user_id='$uid'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)>0)
	{
		$arr=array();
		while(($list=mysqli_fetch_assoc($res))!=false)
		{
			$arr[]=$list;
		}
	}
}
//print_r($arr);//Array ( [0] => Array ( [cart_id] => 74 [color] => #8000ff [size] => XXL [num] => 10 [user_id] => 3 [pid] => 159 )
$sql="select * from ts_product";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)>0)
	{
		$pro=array();
		while(($list=mysqli_fetch_assoc($res))!=false)
		{
			$pro[]=$list;
		}
		//print_r($pro);
	}
}
?>
<!doctype html>
<html>
 <head>
  <title>我的订单</title>
  <meta charset="utf-8"/>
    <style>
  *{margin:0px;padding:0px;}
#big{
	 width:100%;
	 height:780px;
	 border:1px solid red;
	 margin:20px auto;
	}
ul{
	 list-style-type:none;float:left;
	}
li{
	float:left;
	margin-left:15px;
	font-size:0.5em;
	color:#a5a5a5;
	
	}
span{
	float:right;
	}
.p0{
	margin-left:20px;
	}
.xs{
	margin-left:20px;
	height:50px;
	width:auto;
	border:0px solid red;
	}
.xc1{
	font-size:2em;
	margin-right:50px;
	}
#xw{
	width:100%;
	height:40px;
	border:1px solid;
	background:#1F81B0;
	line-height:40px;
	font-size:2.5em;
	
	}
	ul a:-webkit-any-link {text-decoration:none;
    color:white;
    cursor: pointer;}
ul li{margin-left:35px;
    color:white;
	
}
 	
#fl{
	margin-left:50px;
	font-size:1.3em;
	}
#s{float:left;margin-left:30px;font-size:20px;width:200px;height:20px;}
#middle{width:100%;height:auto;border:0px solid red;}
#addr{margin-top:40px;margin-left:200px;}
#car{width:100%;height:auto;border:0px solid red;}
.sp{display:inline-block;} 
.sp{width:70px;display:inline-block;padding:0px;border:0px;background:#fff;}
a{text-decoration:none;color:black;}
	</style>
 </head>

 <body>
<?php include_once("./login_top.php");?>
<div id="s">
	<span class="sp1"><font color="#b6b6b6">当前所在></font>我的购物车</span>
</div>
<div id="middle">
	<div id="addr">
	<form action="do_order_address.php" method="get" name="form" onsubmit="return check()">
		<table border=0 cellspacing=0 width="500px" height="320px">
			<tr>
				<td colspan=2><b>新增收货地址</b></td>	
			</tr>
			<tr>
				<td>收货人:</td>
				<td>
				<input type="text" name="usname" value="" style="width:300px;height:35px;border:1.5px solid #cfcfcf;"/><font color="red">*</font><span id="tip_u" class="sp"></span>
				</td>
			</tr>
			<tr>
				<td>详细地址:</td>
				<td>
				<input type="text" name="addr" value="" style="width:300px;height:35px;border:1.5px solid #cfcfcf;"/><font color="red">*</font><span id="tip_a" class="sp"></span>
				</td>
			</tr>
			<tr>
				<td>联系方式:</td>
				<td>
				<input type="text" name="phone" value="" style="width:300px;height:35px;border:1.5px solid #cfcfcf;"/><font color="red">*</font><span id="tip_p" class="sp"></span>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><input type="checkbox" name="remember" value="1"/>设为默认地址</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<input type="hidden"name="type"value="<?=$type?>">
					<?php if($type==1){?>
						<input type="hidden"name="pid"value="<?=$pid?>">
						<input type="hidden"name="color"value="<?=$color?>">
						<input type="hidden"name="size"value="<?=$size?>">
						<input type="hidden"name="num"value="<?=$num?>">
						<input type="hidden"name="price"value="<?=$price?>">
					<?php } ?>
					<input type="submit" name="sub" value="保存" style="background-color:#6CBDEC; width:120px; height:40px ;color:white;font-size:23px;border-radius:10px;" />
					<input type="submit" name="sub" value="取消" style="background-color:#afafaf; width:120px; height:40px ;color:white;font-size:23px;border-radius:10px;margin-left:50px;" />
				</td>
			</tr>
		</table>
		</form>
	</div>	
	<?php
	$sql="select uid from ts_user where username='$_COOKIE[username]'";
	$res=mysqli_query($link,$sql);
	$res=mysqli_fetch_assoc($res);
	$sql="select * from ts_address where u_id=$res[uid]";
		$res=mysqli_query($link,$sql);
		if(is_object($res))
		{
			if(mysqli_num_rows($res)>0)
			{
				
				$ts_addr=array();
				while(($list=mysqli_fetch_assoc($res))!=false)
				{
					$ts_addr[]=$list;
				}
			}
		}
		?>
		
<br>
<form action="do_order.php" method="get" name="form1">
<?php $sql="select * from ts_address where addr_defalut=1";
		$res=mysqli_query($link,$sql);
		if(is_object($res))
		{
			if(mysqli_num_rows($res)==1)
			{
				$addr=mysqli_fetch_assoc($res);
				$addr_id=$addr['addr_id'];
				$u_id=$addr['u_id'];
			}
		}
		?>
	<p style="margin-left:200px;font-size:1.4em;">
		<?php if(isset($ts_addr)){foreach($ts_addr as $vo){?><!--print_r($addr_id);-->
		 <p><input type="radio" name="addr_id" value="<?php if($vo['addr_defalut']==1){echo $vo['addr_id'];}?>" style="margin-left:200px;"<?php if($vo['addr_defalut']==1){?> checked<?php }?>/>收货人:<?=$vo["consignee"]?>;&nbsp;收货地址:<?=$vo["address"]?>;&nbsp;手机:<?=$vo["mobile"]?>
		 <?php if($type==2){?>
		 	<a href="do_addr_del.php?addr_id=<?=$vo['addr_id']?>&type=<?=$type?>"><font color="#ff0099" style="margin-left:30px;">删除</font></a></p><br>
		 <?php }else{ ?>
			<a href="do_addr_del.php?addr_id=<?=$vo['addr_id']?>&type=<?=$type?>&num=<?=$num?>&color=<?=$color?>&size=<?=$size?>&pid=<?=$pid?>&price=<?=$price?>"><font color="#ff0099" style="margin-left:30px;">删除</font></a></p><br>
		 <?php } }}?>
	
	<div id="car">
	
		<table border=0 width="100%" height="600px" cellspacing=0>
			<tr>
				<td colspan=6><hr color="#bebebe"/></td>
			</tr>
			
			<tr>
				<th width="15%" height="60px">图片</th>
				<th  width="30%">名称</th>
				<th  width="20%">属性</th>
				<th  width="15%">价格</th>
				<th  width="5%">数量</th>
				<th  width="15%">小计</th>
			</tr>
			<tr>
				<td colspan=6><hr color="#bebebe"/></td>
			</tr>
			<?php
				if($_GET['type']==1)
				{	
					extract($_GET);
					$sql="select * from ts_product where pid=$pid";
					$res=mysqli_query($link,$sql);
					if(is_object($res))
					{
						if(mysqli_num_rows($res)==1)
						{
							$onlyone=mysqli_fetch_assoc($res);
							$thumb=$onlyone['thumb'];
							$pname=$onlyone['pname'];
							$num=$num;
							$size=$size;
							if($color[0]!="#"){
								$color="#".$color;
							}
							$price=$price;
							$pid=$pid;

						}
					}
					?>
				<tr>
				<td align="center"><img src="../<?=$thumb?>" width="120px" height="120px"/></td>
				<td align="center"><?=$pname?></td>
				<td align="center">
					颜色:<input type="text" name="color" value="<?=$color?>" style="display:inline-block;background:<?=$color?>;width:30px;"/>
					尺寸:<?=$size?>
				</td>
				<td align="center"><?=$price?></td>
				<td align="center"><?=$num?></td>
				<td align="center">&yen;<?=$price*$num?></td>
			</tr>
				<?php }elseif($_GET['type']==2){
					$total=0;if(isset($arr)){foreach($arr as $v){
					$sql="select * from ts_product where pid".'='.$v['pid'];
					$res=mysqli_query($link,$sql);
					if(is_object($res))
					{
						if(mysqli_num_rows($res)==1)
							{
								$list=mysqli_fetch_assoc($res);
								$thumb=$list['thumb'];
								$price=($list['price']-$list['sprice'])*$v['num'];
								$sums=$list['snums'];
								//print_r($list);
								$total+=$price;
							}
					}
			?>
			<tr>
				<td align="center"><img src="../<?=$thumb?>" width="120px" height="120px"/></td>
				<td align="center"><?=$list['pname']?></td>
				<td align="center">
					颜色:<input type="text" name="color" value="" style="display:inline-block;background:<?=$v['color']?>;width:30px;"/>
					尺寸:<?=$v['size']?>
				</td>
				<td align="center"><?=$list['price']?></td>
				<td align="center"><?=$v['num']?></td>
				<td align="center">&yen;<?=$price?></td>
			</tr>
			<?php }}}?>
			<tr>
				<td colspan=6><hr color="#bebebe"/></td>
			</tr>
			<tr>
				<td colspan=6>
					<span style="float:right;font-size:25px;">商品总价:
					<font color="#f9c164"/>&yen;<?php if($type==1){echo $price*$num;}elseif($type==2){echo $total;}?></font></span>	
				</td>
			</tr>
			<tr>
					<td colspan=6>
						<a href="index.php"><input type="button" name="sub" value="继续购物" style="background-color:#F6F6F6; width:150px; height:45px ;color:black;font-size:28px;float:right;margin-right:0px;" /></a>

						
						<input type="hidden" name="uid" value="<?=$uid?>"><!--用户主键-->
						
						
						<?php if($type==1){?>
						
						<input type="hidden" name="pid" value="<?=$pid?>"><!--商品主键-->
						<input type="hidden" name="type" value="1"/>
						<input type="hidden" name="price" value="<?=$price?>">
						<input type="hidden" name="size" value="<?=$size?>">
						<input type="hidden" name="num" value="<?=$num?>">
						<?php }elseif($type==2){?>
						<?php if(isset($arr)){$pid='';$size='';$color=''; foreach($arr as $k){ $pid.=$k['pid'].",";$size.=$k['size'].",";$color.=$k['color'].",";}$pid=substr($pid,0,-1);$size=substr($size,0,-1);$color=substr($color,0,-1);?>
						
						<input type="hidden" name="pid" value="<?=$pid?>"><!--商品主键-->
						<input type="hidden" name="size" value="<?=$size?>"><!--商品尺寸-->
						<input type="hidden" name="color" value="<?=$color?>"><!--商品颜色-->
						<input type="hidden" name="type" value="2"/>
						<input type="hidden" name="total" value="<?=$total?>">}
						<?php }}?>
						<?php if(isset($ts_addr)){ ?>
						<input type="submit" name="sub" value="提交订单" style="background-color:#6CBDEC; width:150px; height:45px ;color:white;font-size:28px;float:right;margin-right:20px;" />
						<?php } ?>
					</td>
				</tr>
		</table>
		</form>
	</div>
	<div><hr></div>
	</div>	
		<div style="clear:both;width:100%;height:150px;border:0px solid yellow;">
		<?php $sql="select * from ts_news_cate where level=1";
			  $res=mysqli_query($link,$sql);
			  if(is_object($res))
			  {
				  if(mysqli_num_rows($res)>0)
				  {
					$arr=array();
					while(($one=mysqli_fetch_assoc($res))!=false)
					  {
						  $arr[]=$one;
					  }
				  }	?>
					
					<?php foreach($arr as $v)
					{?>
						<div style="float:left;margin-left:250px;border:0px solid red;font-size:16px;margin-top:7px;"><div style="border:px solid blue;font-size:19px;margin-left:-8px;"><?=$v["cname"]?></div>
						<?php $sql="select * from ts_news_cate where fid=$v[cid]";
						$res=mysqli_query($link,$sql);
						if(is_object($res))
						 {
							$arr2=array();
							while(($one1=mysqli_fetch_assoc($res))!=false)
							 {
								$arr2[]=$one1;
							 }
							foreach($arr2 as $vo)
							 {?>
								<div><a href="news.php?cid=<?=$vo['cid']?>"><?=$vo["cname"]?></a></div>
							 <?php }
						 }?>
						</div>
				<?php }
					
			  }
		?>
	</div>
		
		<hr color="#e5e5e5"/>
		<div id="db">
			<div style="margin-left:800px;margin-top:10px;">
				关于我们|法律声明|工作机会|联系我们
			</div>

			<div style="margin-left:600px;margin-top:20px;color:#a8a8a8;">
				Copyright@2013 Thinksite Co.Let night reserved 经营许可证编号：苏A-12345678
			</div>
		</div>
<script type="text/javascript">
	tip_u=document.getElementById("tip_u");
	tip_a=document.getElementById("tip_a");
	tip_p=document.getElementById("tip_p");
	function getValue(obj,tip)
	{
		if(obj.value=="")
		{
			tip.style.color="red";
			tip.innerHTML="不能为空";
		}
		else
		{
			tip.innerHTML="";
		}
	}
	form.usname.onblur=function()
	{
		getValue(form.usname,tip_u);
	}

	form.addr.onblur=function()
	{
		getValue(form.addr,tip_a);
	}
	/*form.phone.onblur=function()
	{
		getValue(form.phone,tip_p);	
	}*/
		preg_m=/^1[3-9]\d{9}$/;
		form.phone.onblur=check;
		function check()
		{
			if(preg_m.test(form.phone.value))
			{
				tip_p.innerHTML="";
				return true;
			}
			else
			{
				tip_p.style.color="red";
				tip_p.innerHTML="请输入大陆手机号";
				return false;
			}
		}
	
	</script>
 </body>
</html>